<?php

class HtmlDatabaseRenderer {

	function Render( &$oConfiguration, &$oDatabase ) {

		$sDatabaseText  = HtmlDatabaseRenderer::RenderHeader( $oConfiguration );
		$sDatabaseText .= HtmlDatabaseRenderer::RenderTables( $oConfiguration, $oDatabase );
		$sDatabaseText .= HtmlDatabaseRenderer::RenderForeignKeys( $oConfiguration, $oDatabase );
		$sDatabaseText .= HtmlDatabaseRenderer::RenderFooter( $oConfiguration );

		return $sDatabaseText;
	}
	
	function RenderTables( &$oConfiguration, &$oDatabase ) {
		
		if ( ! $oConfiguration->GetProperty( 'ShowTables' ) ) {
			return '';	
		}
		
		$sTablesText = HtmlTag::H( 1, 'Tables' );
		
		if ( $oDatabase->HasTables() ) {
			foreach( $oDatabase->GetTables() as $oThisTable ) {
				$sTablesText .= HtmlTableRenderer::Render( $oConfiguration, $oThisTable );
			}
		} else {
			$sTablesText .= 'None';	
		}
		return HtmlTag::Div( $sTablesText, 'Tables', 'Tables' );
	}
	
	function RenderForeignKeys( &$oConfiguration, &$oDatabase ) {
		
		if ( ! $oConfiguration->GetProperty( 'ShowForeignKeys' ) ) {
			return '';
		}

		$aKeys = $oDatabase->GetForeignKeys();

		if ( count( $aKeys ) == 0 ) {
			return '';
		}
		
		$sKeysText = HtmlTag::H( 1, 'Foreign Keys' );
		
		foreach( $aKeys as $oThisForeignKey ) {
			$sKeysText .= HtmlForeignKeyRenderer::Render( $oConfiguration, $oThisForeignKey );
		}
		return HtmlTag::Div( $sKeysText, 'ForeignKeys', 'ForeignKeys' );
	}
	
	function RenderHeader( &$oConfiguration ) {
		return $oConfiguration->GetProperty( 'HtmlHeader' );
	}
	
	function RenderFooter( &$oConfiguration ) {
		return $oConfiguration->GetProperty( 'HtmlFooter' );
	}
}

require_once( 'HtmlTableRenderer.php' );
require_once( 'HtmlForeignKeyRenderer.php' );
require_once( 'HtmlTag.php' );

?>
